package com.foogui.guava;

import com.google.common.collect.HashBasedTable;
import org.junit.Test;

public class TableDemo {
    @Test
    public void table(){
        HashBasedTable<String, String, Integer> table = HashBasedTable.create();
        //存放元素
        table.put("1", "Jan", 20);
        table.put("1", "Feb", 20);
        table.put("2", "Feb", 28);
        //根据row和column取出元素
        System.out.println(table.get("2", "Feb"));
        System.out.println(table.row("1"));
        System.out.println(table.column("Feb"));
        // 转成传统的Map,内外层的键可以自定义
        System.out.println(table.columnMap());
        System.out.println(table.rowMap());
        // 判断是否包含key和value
        System.out.println(table.containsRow("1"));
        System.out.println(table.containsColumn("Feb"));
        System.out.println(table.contains("1", "Feb"));
        System.out.println(table.containsValue(28));
        // 大小
        System.out.println(table.size());
        // 取key或value的集合,会去重
        System.out.println(table.rowKeySet());
        System.out.println(table.columnKeySet());
        System.out.println(table.cellSet());
        System.out.println(table.values());
        System.out.println(table.values());

    }

    @Test
    public void name() {
    }
}
